package com.tg.app.camera;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.alibaba.fastjson.JSON;
import com.appbase.custom.base.DefenceBean;
import com.appbase.custom.base.TemperatureHumiditySettingBean;
import com.appbase.custom.constant.PlaybackConstants;
import com.tange.core.device.facade.DeviceFacade;
import com.tg.app.activity.device.settings.AlertSoundListActivity;
import com.tange.module.device.feature.DeviceFeature;
import com.tg.app.bean.DevicePresetPoints;
import com.tange.base.toolkit.FileUtil;
import com.tg.app.helper.AppHelper;
import com.tg.appcommon.android.Packet;
import com.tange.base.toolkit.StringUtils;
import com.tg.appcommon.android.TGLog;
import com.tg.appcommon.router.TGBusiness;
import com.tg.data.http.entity.DeviceBellBean;
import com.tg.data.http.entity.TimeActionBean;

import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

public class CameraHelper {
    public static final int TCI_CMD_GET_TIMER_TASK = 0x048A;
    public static final int TCI_CMD_GET_TIMER_TASK_RESP = 0x048B;
    public static final int TCI_CMD_SET_TIMER_TASK = 0x0488;
    private static final String TAG = "CameraHelper";

    public static void getPspCMD(@NonNull Camera camera) {
        camera.get2LensesCapZoomCMD();
    }

    public static void getWatchPosCMD(@NonNull Camera camera){
        camera.getWatchPosCMD();
    }

    public static void settWatchPosCMD(@NonNull Camera camera, int channel, int num,  int times){
        byte[] data = AVIOCTRLDEFs.Tcis_SetWatchPosReq.parseContent(channel, num, times);
        camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_SET_WATCHPOS_REQ, data);
    }

    public static void getDeviceRunTimeState(Camera camera){
        if (camera != null) {
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_RUNTIME_STATE_REQ, new byte[4]);
        }
    }

    public static void getLightState(@NonNull Camera camera){
        byte[] data = AVIOCTRLDEFs.Tcis_GetLightReq.parseContent(0);
        camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_LIGHT_REQ, data);
    }

    public static void getLightState(@NonNull DeviceFacade deviceFacade){
        byte[] data = AVIOCTRLDEFs.Tcis_GetLightReq.parseContent(0);
        AppHelper.sendIOCtrl(deviceFacade, AVIOCTRLDEFs.TCI_CMD_GET_LIGHT_REQ, data);
    }


    public static void getPresetPointsEnableCMD(Camera camera) {
        if (camera != null) {
            byte[] data = Packet.intToByteArray_Little(1);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_PSP, data);
        }
    }

    public static void getPtzTracks(Camera camera) {
        if (camera != null) {
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_PTZ_TRACK_REQ, new byte[8]);
        }
    }

    public static void getPtzTracksReqCMD(Camera camera) {
        if (camera != null) {
            byte[] data = Packet.intToByteArray_Little(1);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_PTZ_TRACK_REQ, data);
        }
    }

    public static void getLightData(byte[] data, @NonNull DeviceFeature deviceFeature){
        int id = Packet.byteArrayToShort_Little(data, 0);
        int fMask = Packet.byteArrayToShort_Little(data, 2);
        byte on = Packet.byteArrayToByte_Little(data, 4);
        int mode = Packet.byteArrayToByte_Little(data, 5);
        byte delay_shutdown = Packet.byteArrayToByte_Little(data, 6);
        byte intensity = Packet.byteArrayToByte_Little(data, 7);
        deviceFeature.lightId  = id;
        deviceFeature.lightFMask  = fMask;
        deviceFeature.lightOn  = on == 1;
        deviceFeature.lightDelayShutdown  = delay_shutdown == 1;
        deviceFeature.lightMode  = mode == 1;
        deviceFeature.lightIntensity  = intensity;
    }

    public static boolean isPresetPointsEnable(byte[] data) {
        int cbSize = Packet.byteArrayToShort_Little(data, 0);
        if (cbSize == 12) {
            return true;
        }
        return false;
    }

    public static boolean isCruiseEnable(byte[] data) {
        int cbSize = Packet.byteArrayToInt_Little(data, 0);
        if (cbSize == 1) {
            return true;
        }
        return false;
    }

    public static void getDefenceAudio(Camera camera) {
        if (camera != null) {
            byte[] data = Packet.intToByteArray_Little(PlaybackConstants.ECEVENT_SOUND);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_DEFENCE_REQ, data);
        }
    }


    /**
     * 获取声音报警的开关状态
     * @param camera
     */
    public static void getDefenceEventAudioSwitch(Camera camera) {
        if (camera != null) {
            byte[] data = Packet.intToByteArray_Little(PlaybackConstants.ECEVENT_SOUND);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_EVENT_STATE_REQ, data);
        }
    }

    /**
     * 设置声音报警的开关状态
     * @param camera
     */
    public static void setDefenceEventAudioSwitch(Camera camera, boolean isAudioEventEnabled) {
        if (camera != null) {

            byte[] result = new byte[8];
            byte[] data = Packet.intToByteArray_Little(PlaybackConstants.ECEVENT_SOUND);
            byte[] enabled = Packet.intToByteArray_Little(isAudioEventEnabled ? 1 : 0);

            System.arraycopy(data, 0, result, 0, 4);
            System.arraycopy(enabled, 0, result, 4, 4);

            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_SET_EVENT_STATE_REQ, result);
        }
    }

    public static void setTemper(@NonNull Camera camera, TemperatureHumiditySettingBean temperatureHumiditySettingBean){
        if (temperatureHumiditySettingBean != null){
            byte[] data = Tcis_GetTemperatureSettingReq.parseContent(true, temperatureHumiditySettingBean);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_SET_TEMPERATURE_THRESHOLD, data);
        }
    }

    public static void getTemper(Camera camera){
        if (camera != null) {
            byte[] data = Packet.intToByteArray_Little(0);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_TEMPERATURE_SETTING_REQ, data);
        }
    }

    public static void getHumidity(Camera camera){
        if (camera != null) {
            byte[] data = Packet.intToByteArray_Little(0);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_HUMIDITY_SETTING_REQ, data);
        }
    }

    public static void setHumidity(@NonNull Camera camera, TemperatureHumiditySettingBean temperatureHumiditySettingBean){
        if (temperatureHumiditySettingBean != null){
            byte[] data = Tcis_GetTemperatureSettingReq.parseContent(false, temperatureHumiditySettingBean);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_SET_HUMIDITY_THRESHOLD, data);
        }
    }

    @SuppressLint("DefaultLocale")
    public static DefenceBean getDefencResp(byte[] data) {
        int count = Packet.byteArrayToInt_Little(data, 0);
        TGLog.d(TAG, "Cs2Camera TCI_CMD_GET_DEFENCE_RESP count " + count);
        //目前只有一条记录
        DefenceBean defenceBean = new DefenceBean();
        defenceBean.setFlag(1);
        int event_mask = Packet.byteArrayToInt_Little(data, 12);
        defenceBean.setEventMask(event_mask);
        if (count > 0) {
            int fHour = data[4] & 0xff;
            if (fHour == 0xff) {//0xff
                // 智能布防
                defenceBean.setFlag(0);
            } else {
                byte fMinute = data[5];
                byte tHour = data[8];
                byte tMinute = data[9];
                int day_mask = Packet.byteArrayToInt_Little(data, 20);
                //全天布防
                if (fMinute == 0 && fHour == 0 && tHour == 23 && tMinute == 59 && day_mask == 127) {
                    defenceBean.setStartTime("00:00");
                    defenceBean.setEndTime("23:59");
                    defenceBean.setWeekDays(127);
                    defenceBean.setFlag(1);
                } else {
                    defenceBean.setStartTime(String.format("%02d:%02d", fHour, fMinute));
                    defenceBean.setEndTime(String.format("%02d:%02d", tHour, tMinute));
                    defenceBean.setWeekDays(day_mask);
                    defenceBean.setFlag(2);
                    TGLog.d(TAG, "getDefencResp = " + JSON.toJSONString(defenceBean));
                }
            }
        }
        return defenceBean;
    }



    @SuppressLint("DefaultLocale")
    public static TemperatureHumiditySettingBean getTemperResp(byte[] data) {
        TemperatureHumiditySettingBean settingBean = new TemperatureHumiditySettingBean();

        settingBean.sensor_id = Packet.byteArrayToInt_Little(data, 0);
        settingBean.lo_limit = Packet.byteArrayToInt_Little(data, 4);
        settingBean.lo_limit = settingBean.lo_limit / 1000;
        settingBean.hi_limit = Packet.byteArrayToInt_Little(data, 8);
        settingBean.hi_limit = settingBean.hi_limit / 1000;
        settingBean.lo_en = Packet.byteArrayToInt_Little(data, 12);
        settingBean.hi_en = Packet.byteArrayToInt_Little(data, 16);
        settingBean.lo_threshold = Packet.byteArrayToInt_Little(data, 20);
        settingBean.lo_threshold = settingBean.lo_threshold / 1000;
        settingBean.hi_threshold = Packet.byteArrayToInt_Little(data, 24);
        settingBean.hi_threshold = settingBean.hi_threshold / 1000;
        return settingBean;
    }


    @SuppressLint("DefaultLocale")
    public static TemperatureHumiditySettingBean getHumidityResp(byte[] data) {
        TemperatureHumiditySettingBean settingBean = new TemperatureHumiditySettingBean();

        settingBean.sensor_id = Packet.byteArrayToInt_Little(data, 0);
        settingBean.lo_limit = Packet.byteArrayToInt_Little(data, 4);
        settingBean.lo_limit = settingBean.lo_limit / 10;
        settingBean.hi_limit = Packet.byteArrayToInt_Little(data, 8);
        settingBean.hi_limit = settingBean.hi_limit / 10;
        settingBean.lo_en = Packet.byteArrayToInt_Little(data, 12);
        settingBean.hi_en = Packet.byteArrayToInt_Little(data, 16);
        settingBean.lo_threshold = Packet.byteArrayToInt_Little(data, 20);
        settingBean.lo_threshold = settingBean.lo_threshold / 10;
        settingBean.hi_threshold = Packet.byteArrayToInt_Little(data, 24);
        settingBean.hi_threshold = settingBean.hi_threshold / 10;

        return settingBean;
    }

    public static short getPresetPointsTypeResp(@NonNull byte[] data) {
        return Packet.byteArrayToShort_Little(data, 2);
    }

    public static short getPresetPointsMaxPspResp(@NonNull byte[] data) {
        return Packet.byteArrayToShort_Little(data, 4);
    }

    public static short getCruiseMaxPspResp(@NonNull byte[] data) {
        return Packet.byteArrayToShort_Little(data, 4);
    }

    public static short getCruiseTrackType(@NonNull byte[] data) {
        return Packet.byteArrayToShort_Little(data, 6);
    }



    @NonNull
    public static List<DevicePresetPoints> getPresetPointsResp(byte[] data,boolean isZoomOnly) {
        short size = Packet.byteArrayToShort_Little(data, 0);

        short posType = Packet.byteArrayToShort_Little(data, 2);

        TGLog.d("PrePositionAdapter", "size = " + size + ", posType = " + posType);
        List<DevicePresetPoints> list = new ArrayList<>();
        if (posType == AVIOCTRLDEFs.PSP_BY_POS) {
            for (int i = 0; i < size; i++) {
                int p = 48 * i + 4;
                int flags = Packet.byteArrayToShort_Little(data, p) & AVIOCTRLDEFs.PSP_F_ZOOMONLY;
                short num = Packet.byteArrayToShort_Little(data, p + 2);
                float x = Packet.byteArrayToFloat_Little(data, 4 + p);
                float y = Packet.byteArrayToFloat_Little(data, 8 + p);
                float z = Packet.byteArrayToFloat_Little(data, 12 + p);
                byte[] name = Packet.sub(data, 32, 16 + p);
                AVIOCTRLDEFs.Tcis_SetPtzPosReq ptzPos = new AVIOCTRLDEFs.Tcis_SetPtzPosReq(x, y, z);
                DevicePresetPoints devicePresetPoints = new DevicePresetPoints();
                String nameStr = StringUtils.toString(name);
                if (!TextUtils.isEmpty(nameStr)) {
                    nameStr = nameStr.trim();
                }
                devicePresetPoints.name = nameStr;
                devicePresetPoints.pos = ptzPos;
                devicePresetPoints.flags = flags;
                devicePresetPoints.num = num;
                devicePresetPoints.x = x;
                devicePresetPoints.y = y;
                devicePresetPoints.z = z;
                if (isZoomOnly&&flags==AVIOCTRLDEFs.PSP_F_ZOOMONLY||!isZoomOnly&&num>0){
                    list.add(devicePresetPoints);
                }

            }
        } else if (posType == AVIOCTRLDEFs.PSP_BY_NO) {
            for (int i = 0; i < size; i++) {
                int p = 36 * i + 4;
                int flags = Packet.byteArrayToShort_Little(data, p) & AVIOCTRLDEFs.PSP_F_ZOOMONLY;
                short num = Packet.byteArrayToShort_Little(data, p + 2);
                byte[] name = Packet.sub(data, 32, p + 4);
                TGLog.d("PrePositionAdapter", "num === " + num);
                TGLog.d("PrePositionAdapter", "name === " + name);
                TGLog.d("PrePositionAdapter", "name.length === " + name.length);
                DevicePresetPoints devicePresetPoints = new DevicePresetPoints();
                String nameStr = StringUtils.toString(name);
                if (!TextUtils.isEmpty(nameStr)) {
                    nameStr = nameStr.trim();
                }
                devicePresetPoints.name = nameStr;
                TGLog.d("PrePositionAdapter", "nameStr === " + nameStr);
                devicePresetPoints.num = num;
                devicePresetPoints.flags = flags;
                if (isZoomOnly&&flags==AVIOCTRLDEFs.PSP_F_ZOOMONLY||!isZoomOnly&&num>0){
                    list.add(devicePresetPoints);
                }
            }
        } else if (posType == AVIOCTRLDEFs.PSP_BY_NO_NONAME){
            for (int i = 0; i < size; i++) {
                int p = 4 * i + 4;
                int flags = Packet.byteArrayToShort_Little(data, p) & AVIOCTRLDEFs.PSP_F_ZOOMONLY;
                short num = Packet.byteArrayToShort_Little(data, p + 2);

                DevicePresetPoints devicePresetPoints = new DevicePresetPoints();

                devicePresetPoints.name = "";
                devicePresetPoints.num = num;
                devicePresetPoints.flags = flags;
                if (num>0){
                    list.add(devicePresetPoints);
                }
            }
        }else if (posType == AVIOCTRLDEFs.PSP_BY_POS_NONAME){
            for (int i = 0; i < size; i++) {
                int p = 16 * i + 4;
                int flags = Packet.byteArrayToShort_Little(data, p) & AVIOCTRLDEFs.PSP_F_ZOOMONLY;
                short num = Packet.byteArrayToShort_Little(data, p + 2);
                float x = Packet.byteArrayToFloat_Little(data, 4 + p);
                float y = Packet.byteArrayToFloat_Little(data, 8 + p);
                float z = Packet.byteArrayToFloat_Little(data, 12 + p);

                AVIOCTRLDEFs.Tcis_SetPtzPosReq ptzPos = new AVIOCTRLDEFs.Tcis_SetPtzPosReq(x, y, z);
                DevicePresetPoints devicePresetPoints = new DevicePresetPoints();

                devicePresetPoints.name = "";
                devicePresetPoints.pos = ptzPos;
                devicePresetPoints.flags = flags;
                devicePresetPoints.num = num;
                devicePresetPoints.x = x;
                devicePresetPoints.y = y;
                devicePresetPoints.z = z;
                if (num>0){
                    list.add(devicePresetPoints);
                }
            }
        }
        return list;
    }

    public static void getPtzPosCMD(Camera camera) {

        if (camera != null) {
            camera.getZoomOr2LensesCMD(0);
        }
    }

    public static void setPtzPosReq(Camera camera, AVIOCTRLDEFs.Tcis_SetPtzPosReq req, int channel, int num) {
        if (camera != null && req != null) {
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_SET_PTZ_POS_REQ, AVIOCTRLDEFs.Tcis_SetPtzPosReq.parseContent(req.x, req.y, req.z, channel, num));
        }
    }

    public static void setPresetPoints(Camera camera, int type, DevicePresetPoints points) {
        if (camera != null) {
            byte[] data = AVIOCTRLDEFs.Tcis_GetPresetPointsResp.parseContent(type, 1, points.parseContentEx(type));
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_SET_PSP, data);
        }
    }

    public static void setCruisePresetPoints(Camera camera, int type, DevicePresetPoints points) {
        if (camera != null) {
            byte[] data = AVIOCTRLDEFs.Tcis_GetPresetPointsResp.parseContent(type, 1, points.parseContentEx(type));
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_SET_PSP, data);
        }
    }

    public static void playLampAudio(@NonNull Camera camera, int id, short type, int fileFormats, int audioCodecs, byte[] content){
        byte[] data = AVIOCTRLDEFs.Tcis_SetAlarmTone_Req.parseContent(id, type, fileFormats, audioCodecs, content);
        camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_PLAY_AUDIO_REQ, data);
    }

    public static void playLampAudio(Context context, @NonNull Camera camera, DeviceBellBean deviceBellBean, int fileFormats, int audioCodecs){
        byte[] data;
        if (StringUtils.equals(deviceBellBean.getId(), AlertSoundListActivity.DEFAULT_ID)){
            data = FileUtil.readFileFromAssets(context, deviceBellBean.getName());
        }else{
            String path = TGBusiness.getLampModule().getLampPath(deviceBellBean.getName());
            data = FileUtil.readFile(new File(path));
        }

        CameraHelper.playLampAudio(camera, 0, (short) 0, fileFormats, audioCodecs, data);
    }

    public static void deletedPresetPoints(Camera camera, int type, List<DevicePresetPoints> pointsList) {
        if (pointsList == null || pointsList.size() == 0) return;
        if (camera == null) {
            return;
        }
        int size = pointsList.size();
        int len = 48;
        if (type == AVIOCTRLDEFs.PSP_BY_NO){
            len = 36;
        }else if (type == AVIOCTRLDEFs.PSP_BY_NO_NONAME){
            len = 4;
        }else if (type == AVIOCTRLDEFs.PSP_BY_POS_NONAME){
            len = 16;
        }
        TGLog.d("PrePositionAdapter", " len ====== " + len);
        ByteBuffer buffer = ByteBuffer.allocate(len * size);

        for (DevicePresetPoints p : pointsList) {
            buffer.put(p.parseDeleteContent(type));
        }
        byte[] data = AVIOCTRLDEFs.Tcis_GetPresetPointsResp.parseContent(type, size, buffer.array());
        camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_SET_PSP, data);
    }

    public static AVIOCTRLDEFs.Tcis_SetPtzPosReq getPtzPosResp(byte[] data) {
        float x = Packet.byteArrayToFloat_Little(data, 0);
        float y = Packet.byteArrayToFloat_Little(data, 4);
        float z = Packet.byteArrayToFloat_Little(data, 8);
        AVIOCTRLDEFs.Tcis_SetPtzPosReq ptzPos = new AVIOCTRLDEFs.Tcis_SetPtzPosReq(x, y, z);
        TGLog.d(TAG, "Tcis_GetPtzPosReq : [%f,%f,%f] ", x, y, z);
        return ptzPos;
    }

    public static int getSetCommand(byte[] data) {

        int command = Packet.byteArrayToInt_Little(data, 0);
        TGLog.d(TAG, "TCI_CMD_SET_COMMAND_RESP command:[%x] ", command);
        return command;
    }

    public static int getSetCommandResult(byte[] data) {
        int result = Packet.byteArrayToInt_Little(data, 4);
        TGLog.d(TAG, "TCI_CMD_SET_COMMAND_RESP result:[%d] ", result);
        return result;
    }


    public static void getBodyDetectionFrame(Camera camera) {
        if (camera != null) {
            byte[] data = Packet.intToByteArray_Little(0);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_GET_SHOW_BOX_REQ, data);
        }
    }
    public static void setLocateInPicPoints(Camera camera, int ch, float x,float y) {
        if (camera != null) {
            byte[] data = AVIOCTRLDEFs.Tcis_LocateInPicReq.parseContent(ch,x, y,0);
            camera.sendIOCtrl(AVIOCTRLDEFs.TCI_CMD_LOCATE_IN_PIC_REQ, data);
        }
    }

    public static byte[] parseContent(int x, int y, int zoom, int control, int channel) {
        byte[] result = new byte[20];
        byte[] bX = Packet.intToByteArray_Little(x);
        System.arraycopy(bX, 0, result, 0, 4);
        byte[] bY = Packet.intToByteArray_Little(y);
        System.arraycopy(bY, 0, result, 4, 4);
        byte[] bZ = Packet.intToByteArray_Little(zoom);
        System.arraycopy(bZ, 0, result, 8, 4);
        byte[] ch = Packet.intToByteArray_Little(channel);
        System.arraycopy(ch, 0, result, 12, 4);


        byte[] controls = Packet.intToByteArray_Little(control);
        System.arraycopy(controls, 0, result, 16, 4);
        return result;
    }

    public static void sendPTZCMDShort(@NonNull Camera camera, int control, int channel) {
        CameraHelper.sendPTZCMDShort(camera, 0, 0, 0, control, channel);
    }


    public static void sendPTZCMDShort(@NonNull Camera camera, int x, int y, int z, int control, int channel) {
        camera.sendIOCtrl(4096, CameraHelper.parseContent(x, y, z, control, channel));
    }

    public static byte[] parseTimeActionContent(List<TimeActionBean> list) {
        int size = 0;
        int items = 0;
        for (int i = 0; i < list.size(); i++){
            if (list.get(i).oldState != 1){
                size += list.get(i).size;
                items++;
            }
        }

        byte[] result = new byte[size + 8];

        byte[] objects = Packet.intToByteArray_Little(1);
        System.arraycopy(objects, 0, result, 0, 4);

        byte[] nItems = Packet.intToByteArray_Little(items);
        System.arraycopy(nItems, 0, result, 4, 4);

        int p = 8;
        for (int i = 0; i < list.size(); i++){
            if (list.get(i).oldState == 1){
                continue;
            }
            byte[] s = Packet.intToByteArray_Little(list.get(i).size);
            System.arraycopy(s, 0, result, p, 4);

            result[p+4] = list.get(i).from.hour;
            result[p+5] = list.get(i).from.minute;
            result[p+6] = list.get(i).from.second;
            result[p+7] = list.get(i).from.reserved;

            result[p+8] = list.get(i).to.hour;
            result[p+9] = list.get(i).to.minute;
            result[p+10] = list.get(i).to.second;
            result[p+11] = list.get(i).to.reserved;

            byte[] state = Packet.shortToByteArray_Little(list.get(i).state);
            byte[] repeat = Packet.shortToByteArray_Little(list.get(i).repeat);
            byte[] action = Packet.intToByteArray_Little(list.get(i).action);

            System.arraycopy(state, 0, result, p+12, 2);
            System.arraycopy(repeat, 0, result, p+14, 2);
            System.arraycopy(action, 0, result, p+16, 4);

            p += list.get(i).size;

        }

        return result;
    }

    public static byte[] parseContent() {
        byte[] result = new byte[4];
        byte[] types = Packet.shortToByteArray_Little((short) 1);
        byte[] ids = Packet.shortToByteArray_Little((short) 0);
        System.arraycopy(types, 0, result, 0, 2);
        System.arraycopy(ids, 0, result, 2, 2);
        return result;
    }

    public static void sendCMDTimerTask(@NonNull Camera camera, List<TimeActionBean> list){
        camera.sendIOCtrl(TCI_CMD_SET_TIMER_TASK, CameraHelper.parseTimeActionContent(list));
    }


    public static void getCMDTimerTask(@NonNull DeviceFacade deviceFacade){
        AppHelper.sendIOCtrl(deviceFacade, TCI_CMD_GET_TIMER_TASK, CameraHelper.parseContent());
    }

    public static void getAlarmToneCap(@NonNull DeviceFacade deviceFacade) {
        AppHelper.sendIOCtrl(deviceFacade, AVIOCTRLDEFs.TCI_CMD_GET_ALARMTONE_CAP_REQ, new byte[4]);
    }
}
